#include "stdafx.h"
#include "PixelbufferObject.h"
#include <iostream>
#include <Utilities\glext.h>
#include <Utilities\Extensions.h>

using namespace std;

PixelbufferObject::PixelbufferObject(void)
{
	glGenBuffers(1, &_PBOObject);
}

PixelbufferObject::~PixelbufferObject(void)
{
	glDeleteBuffers(1, &_PBOObject);
}

void PixelbufferObject::Create(const GLint size)
{
	_size = size;

	Bind();
	glBufferData(GL_PIXEL_UNPACK_BUFFER, size, 0, GL_STREAM_DRAW);
	Disable();
}

GLvoid* const PixelbufferObject::MapResetBuffer(void)
{
	glBufferData(GL_PIXEL_UNPACK_BUFFER, _size, 0, GL_STREAM_DRAW);
	return glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
}

void PixelbufferObject::Bind(void) const
{
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _PBOObject);
}

void PixelbufferObject::UnmapBuffer(void)
{
	glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
}

void PixelbufferObject::Disable(void)
{
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}